<?php
class StoreModel
{
    /*
        通过药店id获取药店信息
        params
            store_id 药店id
            field 需要查询的字段名称
    */
    public function getStoreInfoById($store_id = 0, $field = '*')
    {
        $Dao = M("okdkyao.dk_app_yaodian");

        $where = sprintf("ID = %d", $store_id);
        $storeInfo = $Dao
            ->field($field)
            ->where($where)
            ->find();

        return $storeInfo;
    }

    /*
        通过城市CID获取城市信息列表
        params
            CID
            field 需要查询的字段名称
    */
    public function getCityInfoById($cid = '')
    {
        $Dao = M("okdkyao.dk_app_area_city");

        $where = sprintf("ID = %d", $cid);
        $cityInfo = $Dao
            ->where($where)
            ->find();

        return $cityInfo;
    }

    /*
        通过药店id获取用户手机号码
        params
            store_id 订单id
    */
    public function getStoreMobileById($store_id = 0)
    {
        $Dao = M("okdkyao.dk_sj_user");

        $where = sprintf(" YID = %d", $store_id);

        $userInfo = $Dao
            ->field("UserID")
            ->where($where)
            ->find();

        return $userInfo['UserID'];
    }

    /*
        通过区域AID获取区域信息
        params
            field 需要查询的字段名称
    */
    public function getAreaInfoByAreaId($area_id = '')
    {
        $Dao = M("okdkyao.dk_app_area");

        $where = sprintf("ID = %d", $area_id);
        $areaInfo = $Dao
            ->where($where)
            ->find();

        return $areaInfo;
    }

    /*
         通过区域AID获取区域经纬度信息
         params
             area_id 区域id
    */
    public function getAreaPointByAreaId($area_id = 0)
    {
        $Dao = M("okdkyao.dk_app_area_jw");

        $where = sprintf("AID = %d AND State = 1", $area_id);
        $areaInfo = $Dao
            ->field("JinDuX, WeiDuY")
            ->where($where)
            ->order("ONum asc")
            ->select();

        
        return $areaInfo;
    }


    /*
        获取药店经纬度信息
        params
            store_id 药店id
    */
    public function getStoreLocation($store_id = '')
    {
        $storeInfo = $this->getStoreInfoById($store_id, "JinDuX,WeiDuY");


        if(empty($storeInfo['JinDuX']) || empty($storeInfo['WeiDuY'])){
            return "-180,-90";
        }

        $location = getPointLocation($storeInfo['JinDuX'], $storeInfo['WeiDuY']);

        return $location;
    }
}
?>